# -*- coding: utf-8 -*- 
# @Time : 2021/7/11 17:33 
# @Author : Dong 
# @File : function_logging.py


import logging
import logging.handlers

logger = logging.getLogger("__name__")

# 标准输出
handler1 = logging.StreamHandler()

# 输出到文件
handler2 = logging.FileHandler(filename="test.txt")

logger.setLevel(logging.DEBUG)
handler1.setLevel(logging.WARNING)
handler2.setLevel(logging.DEBUG)

formatter = logging.Formatter("%(asctime)s %(name)s %(levelname)s %(message)s")
handler1.setFormatter(formatter)
# handler2.setFormatter(formatter)
handler2 = logging.handlers.RotatingFileHandler('test.txt',mode='W',maxBytes=500,backupCount=3)

logger.addHandler(handler1)
logger.addHandler(handler2)

logger.debug('This is debug message.')
logger.info('This is info message.')
logger.warning('This is warning message.')
logger.error('This is error message.')
logger.critical('This is critical message.')